import 'package:flutter/material.dart';

class RepairTaskCard extends StatelessWidget {
  final String status;
  final String reporter;
  final String productionLine;
  final String reportTime;
  final String device;
  final String startTime;
  final String fault;
  final String endTime;
  final VoidCallback? onStartRepair;
  final VoidCallback? onEndRepair;

  const RepairTaskCard({
    super.key,
    required this.status,
    required this.reporter,
    required this.productionLine,
    required this.reportTime,
    required this.device,
    required this.startTime,
    required this.fault,
    required this.endTime,
    this.onStartRepair,
    this.onEndRepair,
  });

  @override
  Widget build(BuildContext context) {
    return Card(
      elevation: 8,
      margin: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(16),
      ),
      child: Container( // 这是Card的直接child
        width: double.infinity,
        padding: const EdgeInsets.all(0),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(16),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 标题区域
            _buildHeaderSection(),

            // 内容区域
            Padding(
              padding: const EdgeInsets.all(16),
              child: Column(
                children: [
                  // 第一行信息
                  _buildInfoRow(
                    label: '产线：$productionLine',
                    value: '报修时间：$reportTime',
                    button: _buildActionButton(
                      text: '开始维修',
                      color: Colors.orange,
                      onPressed: onStartRepair,
                    ),
                  ),

                  const SizedBox(height: 16),

                  // 第二行信息
                  _buildInfoRow(
                    label: '设备：$device',
                    value: '开始时间：$startTime',
                    button: _buildActionButton(
                      text: '结束维修',
                      color: Colors.deepOrange,
                      onPressed: onEndRepair,
                    ),
                  ),

                  const SizedBox(height: 16),

                  // 第三行信息
                  _buildInfoRow(
                    label: '故障：$fault',
                    value: '结束时间：$endTime',
                    button: null,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  // 构建标题区域
  Widget _buildHeaderSection() {
    return Container(
      padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
      decoration: const BoxDecoration(
        color: Color(0xFFE3F2FD), // 淡蓝色背景
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(16),
          topRight: Radius.circular(16),
        ),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
        Text(
        status,
        style: const TextStyle(
          fontSize: 18,
          fontWeight: FontWeight.bold,
          color: Color(0xFF1976D2),
        )),
        Text(
          '报修人：$reporter',
          style: TextStyle(
            fontSize: 16,
            color: Colors.grey[700],
          ),
        ),
        ],
      ),
    );
  }

  // 构建信息行
  Widget _buildInfoRow({
    required String label,
    required String value,
    required Widget? button,
  }) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        // 左侧信息区域
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
            Text(
            label,
            style: const TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.w500,
              color: Color(0xFF2D3748),
            )),
            const SizedBox(height: 6),
            Text(
              value,
              style: TextStyle(
                fontSize: 14,
                color: Colors.grey[700],
              ),
            ),
            ],
          ),
        ),

        // 右侧按钮区域（如果有按钮）
        if (button != null) button,
      ],
    );
  }

  // 构建操作按钮
  Widget _buildActionButton({
    required String text,
    required Color color,
    VoidCallback? onPressed,
  }) {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: color.withOpacity(0.4),
            blurRadius: 6,
            offset: const Offset(0, 3),
          )
        ],
      ),
      child: ElevatedButton(
        onPressed: onPressed,
        style: ElevatedButton.styleFrom(
          backgroundColor: color,
          foregroundColor: Colors.white,
          padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 16),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(8),
          ),
          elevation: 0, // 使用自定义阴影替代默认阴影
        ),
        child: Text(
          text,
          style: const TextStyle(
            fontSize: 14,
            fontWeight: FontWeight.bold,
          ),
        ),
      ),
    );
  }
}